package com.travel.controller.admin;

import com.travel.constant.ApiConstants;
import com.travel.model.dto.common.ApiResponse;
import com.travel.model.entity.auth.User;
import com.travel.service.Service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
//管理员用户管理接口 , 获取所有用户, 更新用户状态
@Tag(name = "管理员用户", description = "管理员用户管理接口")
@RestController
@RequestMapping(ApiConstants.API_ADMIN + "/users")
@RequiredArgsConstructor
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
public class AdminUserController {
    private final UserService userService;

    @Operation(summary = "获取所有用户", description = "管理员获取所有用户信息")
    @GetMapping
    public ApiResponse<Page<User>> getAllUsers(
            @Parameter(description = "分页信息") Pageable pageable) {
        Page<User> users = userService.getAllUsers(pageable);
        return ApiResponse.success("获取成功", users);
    }

    @Operation(summary = "更新用户状态", description = "管理员更新用户状态")
    @PutMapping("/{id}/status")
    public ApiResponse<User> updateUserStatus(
            @Parameter(description = "用户ID") @PathVariable Long id,
            @Parameter(description = "用户状态") @RequestParam Integer status) {
        userService.updateUserStatus(id, status);
        User user = userService.getUserById(id);
        return ApiResponse.success("更新成功", user);
    }
} 